package com.bank.frame;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;

import com.bank.utils.SystemConstants;

public class AdminPanel extends JPanel {
	private static JDesktopPane contentPanel = new JDesktopPane();// 主面板

	public AdminPanel() {
		this.setBounds(0, 0, SystemConstants.FRAME_WIDTH, SystemConstants.FRAME_HEIGHT);
		contentPanel.setBounds(0, 20, SystemConstants.FRAME_WIDTH, SystemConstants.FRAME_HEIGHT - 50);
		this.add(contentPanel, BorderLayout.CENTER);// 中间
		JMenuBar menuBar = new JMenuBar();// 菜单栏的容器
		JMenu parentMenu = new JMenu("账户管理");// 菜单1
		JMenu systemMenu = new JMenu("退出登录");// 菜单2
		menuBar.add(parentMenu);// 将一级菜单放入容器
		menuBar.add(systemMenu);

		//点击账户管理后的界面
		parentMenu.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				setContent(new AdminAccountTablePanel());
			}
		});
		//点击退出登录后返回原界面
		systemMenu.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				contentPanel.removeAll();// 重新绘制窗口
				contentPanel.repaint();
				com.bank.frame.MainFrame.setContent(new com.bank.frame.LoginPanel());
			}
		});

		this.setLayout(new BorderLayout());
		menuBar.setBounds(0, 0, SystemConstants.FRAME_WIDTH, 50);// 菜单栏
		this.add(menuBar, BorderLayout.NORTH);// 上(北)
	}

	public static void setContent(JInternalFrame internalFrame) {
		internalFrame.setSize(SystemConstants.FRAME_WIDTH - 100, SystemConstants.FRAME_HEIGHT - 100);
		// 显示内部窗口
		internalFrame.setVisible(true);
		contentPanel.removeAll();// 重新绘制窗口
		contentPanel.repaint();
		contentPanel.add(internalFrame);
	}
}
